package com.ruoyi.funding.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.RemoteResearcherService;
import com.ruoyi.system.api.domain.Researcherinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.funding.domain.Reimbursement;
import com.ruoyi.funding.service.IReimbursementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.domain.R;

/**
 * 报销记录Controller
 * 
 * @author ycl
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/reimbursement")
public class ReimbursementController extends BaseController
{
    @Autowired
    private IReimbursementService reimbursementService;

    @Autowired
    private RemoteResearcherService researcherService;

    /**
     * 查询报销记录列表
     */
    @RequiresPermissions("funding:reimbursement:list")
    @GetMapping("/list")
    public TableDataInfo list(Reimbursement reimbursement)
    {
        startPage();
        List<Reimbursement> list = reimbursementService.selectReimbursementList(reimbursement);

        for(Reimbursement reimbursement1:list){
           R<Researcherinfo> r = researcherService.getInfo1(reimbursement1.getReimbursedBy());
           Researcherinfo researcherinfo = r.getData();
           reimbursement1.setResearcherName(researcherinfo.getResearcherName());

        }

        return getDataTable(list);
    }

    /**
     * 导出报销记录列表
     */
    @RequiresPermissions("funding:reimbursement:export")
    @Log(title = "报销记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reimbursement reimbursement)
    {
        List<Reimbursement> list = reimbursementService.selectReimbursementList(reimbursement);
        ExcelUtil<Reimbursement> util = new ExcelUtil<Reimbursement>(Reimbursement.class);
        util.exportExcel(response, list, "报销记录数据");
    }

    /**
     * 获取报销记录详细信息
     */
    @RequiresPermissions("funding:reimbursement:query")
    @GetMapping(value = "/{reimbursementId}")
    public AjaxResult getInfo(@PathVariable("reimbursementId") Long reimbursementId)
    {
        return success(reimbursementService.selectReimbursementByReimbursementId(reimbursementId));
    }

    /**
     * 新增报销记录
     */
    @RequiresPermissions("funding:reimbursement:add")
    @Log(title = "报销记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reimbursement reimbursement)
    {
        return toAjax(reimbursementService.insertReimbursement(reimbursement));
    }

    /**
     * 修改报销记录
     */
    @RequiresPermissions("funding:reimbursement:edit")
    @Log(title = "报销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reimbursement reimbursement)
    {
        return toAjax(reimbursementService.updateReimbursement(reimbursement));
    }

    /**
     * 删除报销记录
     */
    @RequiresPermissions("funding:reimbursement:remove")
    @Log(title = "报销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reimbursementIds}")
    public AjaxResult remove(@PathVariable Long[] reimbursementIds)
    {
        return toAjax(reimbursementService.deleteReimbursementByReimbursementIds(reimbursementIds));
    }
}
